﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using KorbeRTR.Utility;

namespace KorbeRTR
{
    public partial class FormInfo : Form
    {
        public FormInfo(string msg,double min,double max)
        {
            InitializeComponent();
            lblInfo.Text = msg;

            Min = min;
            Max = max;

            ok = false;
        }

        private double Min;
        private double Max;

        public string input;
        public bool ok;

        private void btn取消_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void OK()
        {
            input = txtValue.Text;

            if (input.ToDouble() >= Min && input.ToDouble() <= Max)
            {

                ok = true;
                Close();
            }
            else
            {
                MessageBox.Show("输入数据不正确，请重新输入", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtValue.Text = "";
                txtValue.Focus();
            }
        }

        private void btn确定_Click(object sender, EventArgs e)
        {
            OK();
        }

        private void FormInfo_Load(object sender, EventArgs e)
        {
         
        }

        private void txtValue_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(e.KeyChar != 8 && !Char.IsDigit(e.KeyChar)&&e.KeyChar!='.')
            {
                e.Handled = true;
            }
        }

        private void txtValue_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                OK();
                e.Handled = true;
            }
        }
    }
}
